//
//  EFOrderTranseCell.m
//  EnjogFood
//
//  Created by 王芳 on 17/5/17.
//  Copyright © 2017年 wf. All rights reserved.
//

#import "EFOrderTranseCell.h"
#import "EFOrderTranseItem.h"

@interface EFOrderTranseCell ()
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *detailLabel;
@property (strong, nonatomic) UILabel *subDetailLabel;
@property (strong, nonatomic) UIImageView *arrowImageV;
@property (strong, nonatomic) UIView *line;
@end

@implementation EFOrderTranseCell

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

- (void)initUI{
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.detailLabel];
    [self.contentView addSubview:self.arrowImageV];
    [self.contentView addSubview:self.line];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    self.line.left = 20;
    self.line.bottom = self.height;
}

- (void)setObject:(EFOrderTranseItem *)item{
    self.titleLabel.text = @"物流：";
    [self.titleLabel sizeToFit];
    self.titleLabel.left = 20;
    self.titleLabel.top = (self.height - self.titleLabel.height)/2;
    
    self.detailLabel.text= [NSString stringWithFormat:@"%@(%@)",item.tracking_no,item.carrier];
    [self.detailLabel sizeToFit];
    self.detailLabel.left = self.titleLabel.right;
    self.detailLabel.top = self.titleLabel.top;
    
    if (item.post_message.length >0) {
         [self.contentView addSubview:self.subDetailLabel];
        self.subDetailLabel.text = item.post_message;
        [self.subDetailLabel sizeToFit];
        self.subDetailLabel.top = self.titleLabel.bottom + 8;
        self.subDetailLabel.left = 20;
    }
    self.arrowImageV.top = 19;
    self.arrowImageV.right = kScreenWidth - 20;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = kBlack999;
    }
    return _titleLabel;
}

- (UILabel *)detailLabel{
    if (!_detailLabel) {
        _detailLabel = [[UILabel alloc] init];
        _detailLabel.font = [UIFont systemFontOfSize:13];
        _titleLabel.textColor = kBlack333;
    }
    return _detailLabel;
}

- (UILabel *)subDetailLabel{
    if (!_subDetailLabel) {
        _subDetailLabel = [[UILabel alloc] init];
        _subDetailLabel.font = [UIFont systemFontOfSize:13];
        _subDetailLabel.textColor = RGBCOLOR(0xe65a33);
    }
    return _subDetailLabel;
}

- (UIImageView *)arrowImageV{
    if (!_arrowImageV) {
        _arrowImageV = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 8, 8)];
        _arrowImageV.image = IMG(@"more_icon_me_default");
    }
    return _arrowImageV;
}

+ (CGFloat)cellHeight:(EFOrderTranseItem *)item{
    if (item.post_message.length > 0) {
        return 64;
    }
    return 40;
}

- (UIView *)line{
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth - 2*20, 1)];
        _line.backgroundColor = RGBCOLOR(0xececec);
    }
    return _line;
}


@end
